<template>
  <div class="input-group">
    <input v-model="newTodo" @keyup.enter="addTodo" placeholder="Add a new todo" />
    <button @click="addTodo">Add</button>
  </div>
</template>

<script setup>
import { ref } from 'vue';
// import { defineEmits } from 'vue';

const newTodo = ref('');

const emit = defineEmits(['add-todo']);

function addTodo() {
  if (newTodo.value.trim() !== '') {
    emit('add-todo', newTodo.value.trim());
    newTodo.value = '';
  }
}
</script>

<style scoped>
.input-group {
  display: flex;
  align-items: center;
}

input {
  padding: 10px;
  margin-right: 10px;
  width: 200px;
}

button {
  padding: 10px 20px;
  cursor: pointer;
  background-color: #ffcccc; /* 浅红色背景 */
  border: none;
  border-radius: 5px;
}

button:hover {
  background-color: #ff9999; /* 悬停时的浅红色背景 */
}
</style>